import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/login',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/taskManagement',
    component: Layout,
    redirect: 'addTask',
    meta: { title: '任务管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'addTask',
        name: 'AddTask',
        component: () => import('@/views/taskManagement/addTask/addTask'),
        meta: { title: '任务管理', icon: '' }
      },
      {
        hidden: true,
        path: 'addSubTask',
        name: 'addSubTask',
        component: () => import('@/views/taskManagement/addSubTask'),
        meta: { title: '新增子任务', icon: '' }
      },
      {
        hidden: true,

        path: 'TaskManagementList',
        name: 'TaskManagementList',
        component: () => import('@/views/taskManagement/mainTaskList'),
        meta: { title: '任务列表', icon: '' }
      },
      {
        hidden: true,

        path: 'subTaskLisk',
        name: 'subTaskLisk',
        component: () => import('@/views/taskManagement/subTaskLisk'),
        meta: { title: '子任务列表', icon: '' }
      }
    ]
  },
  {
    path: '/npc',
    component: Layout,
    redirect: 'addNpc',
    meta: { title: 'NPC管理', icon: 'el-icon-s-help' },
    children: [{
      path: 'npc',
      name: 'NPC',
      component: () => import('@/views/npc/index'),
      meta: { title: 'NPC管理', icon: '' }
    }]
  },
  {
    path: '/arsbt',
    component: Layout,
    redirect: 'arsbtlist',
    meta: { title: '识别图管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'arsbtlist',
        name: 'arsbtlist',
        component: () => import('@/views/arsbt/arsbtlist'),
        meta: { title: '识别图列表', icon: '' }
      },
      {
        path: 'arsbtAdd',
        name: 'arsbtAdd',
        component: () => import('@/views/arsbt/arsbtAdd'),
        meta: { title: '新增识别图', icon: '' }
      }
    ]
  },
  {
    path: '/prop',
    component: Layout,
    redirect: '/prop/index',
    name: 'Example',
    meta: { title: '道具管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'index',
        name: 'table',
        component: () => import('@/views/prop/index'),
        meta: { title: '道具列表', icon: 'table' }
      },
      {
        hidden: true,
        path: 'addOrUpdateProp',
        name: 'addOrUpdateProp',
        component: () => import('@/views/prop/addOrUpdateProp'),
        meta: { title: '---', icon: 'table' }
      }
    ]
  },
  {
    path: '/xianfa',
    component: Layout,
    redirect: '/xianfa/index',
    name: 'Example',
    meta: { title: '仙法列表', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'index',
        name: 'table',
        component: () => import('@/views/xianfa/index'),
        meta: { title: '仙法列表', icon: 'table' }
      }
    ]
  },
  {
    path: '/hecheng',
    component: Layout,
    redirect: '/hecheng/index',
    name: 'Example',
    meta: { title: '合成列表', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'index',
        name: 'table',
        component: () => import('@/views/hecheng/index'),
        meta: { title: '合成列表', icon: 'table' }
      },
      {
        hidden: true,
        path: 'addOrUpdateHeCheng',
        name: 'addOrUpdateHeCheng',
        component: () => import('@/views/hecheng/addOrUpdateHeCheng'),
        meta: { title: '---', icon: 'table' }
      }
    ]
  },

  {
    path: '/account',
    component: Layout,
    redirect: '/account/index',
    name: 'Example',
    meta: { title: '账号列表', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'index',
        name: 'table',
        component: () => import('@/views/account/index'),
        meta: { title: '账号列表', icon: 'table' }
      },
      {
        hidden: true,
        path: 'accountUpdate',
        name: 'accountUpdate',
        component: () => import('@/views/account/accountUpdate'),
        meta: { title: '---', icon: 'table' }
      }
    ]
  },

  {
    path: '/gameroleinfo',
    component: Layout,
    redirect: '/gameroleinfo/index',
    name: '角色信息',
    meta: { title: '角色信息', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'index',
        name: '角色信息',
        component: () => import('@/views/gameroleinfo/index'),
        meta: { title: '角色信息', icon: 'table' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
